<?php

/**
 * This is the model class for table "TeacherReservations".
 *
 * The followings are the available columns in table 'TeacherReservations':
 * @property string $id
 * @property string $user_id
 * @property string $start_date
 * @property string $end_date
 * @property string $description
 * @property string $is_deleted
 * @property string $keeper_reservations_id
 * @property integer $limit
 *
 * The followings are the available model relations:
 * @property StudentReservations[] $studentReservations
 * @property Users $user
 * @property KeeperReservations $keeperReservations
 */
class TeacherReservations extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return TeacherReservations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'TeacherReservations';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, start_date, end_date, keeper_reservations_id, limit', 'required'),
			array('limit', 'numerical', 'integerOnly'=>true),
			array('user_id, keeper_reservations_id', 'length', 'max'=>20),
			array('description', 'length', 'max'=>45),
			array('is_deleted', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, user_id, start_date, end_date, description, is_deleted, keeper_reservations_id, limit', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'studentReservations' => array(self::HAS_MANY, 'StudentReservations', 'teacher_reservations_id'),
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
			'keeperReservations' => array(self::BELONGS_TO, 'KeeperReservations', 'keeper_reservations_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_id' => 'User',
			'start_date' => 'Start Date',
			'end_date' => 'End Date',
			'description' => 'Description',
			'is_deleted' => 'Is Deleted',
			'keeper_reservations_id' => 'Keeper Reservations',
			'limit' => 'Limit',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('start_date',$this->start_date,true);
		$criteria->compare('end_date',$this->end_date,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('is_deleted',$this->is_deleted,true);
		$criteria->compare('keeper_reservations_id',$this->keeper_reservations_id,true);
		$criteria->compare('limit',$this->limit);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}